<template>
  <div class="data-content">
    <div class="header">
      <div class="header-title">
        <div class="data-name elliptical-1" :title="propValue?.dataFileName">{{ propValue?.dataFileName }}</div>
        <div class="data-line"></div>
        <div class="data-size">{{ sizeFilter(propValue?.dataUrls?.fileSize as number) || '' }}</div>
      </div>
      <div class="header-down">
        <a-button
          type="text"
          class="icon-only-btn button-padding"
          @click.stop="handleToDownload(propValue?.dataUrl, propValue?.dataFileName)"
        >
          <i class="iconfont icon-download-2-line"></i><span>下载数据集</span>
        </a-button>
      </div>
    </div>
    <div v-if="propValue?.dataUrls?.fileUrls?.length" class="image-content">
      <a-image
        v-for="(item, index) in propValue?.dataUrls?.fileUrls"
        :key="index"
        :src="customImgUrl(item, 207, 130)"
        alt="数据集图片"
        :fallback="defaultImageUrl"
        :preview="false"
      />
    </div>
    <default-graph v-else height="384px" title="">
      <a-empty :image="simpleImage" description="暂无文件" />
    </default-graph>
    <div v-show="propValue?.dataUrls?.fileUrls?.length > 48" class="down-more">下载查看更多</div>
  </div>
</template>

<script lang="ts" setup>
  import { message } from 'ant-design-vue'
  import { Empty } from 'ant-design-vue'
  import { debounce, sizeFilter } from 'g6-fn'

  import defaultImageUrl from '@/assets/img/imageFailed.svg'
  import defaultGraph from '@/components/DefaultGraph/index.vue'
  import { customImgUrl } from '@/utils'

  import { DetailType } from '../../types'

  export interface Props {
    propValue?: DetailType
  }

  const simpleImage = Empty.PRESENTED_IMAGE_SIMPLE

  withDefaults(defineProps<Props>(), {})

  //下载
  const handleToDownload = debounce(async (dataUrl: string, dataFileName: string): Promise<void> => {
    message.success({ content: '开始下载' })
    window.open(dataUrl)
    console.log(dataFileName)

    // try {
    //   const { data } = await minioApi.download({ fileName: dataUrl })
    //   waitLoading<ResponseData<any>>(fetchDownload(data, dataFileName), {
    //     loadingText: '数据准备中,请耐心等待...',
    //     errorText: '文件下载失败'
    //   })
    // } catch (error) {
    //   manualMessage.destroy()
    //   message.error({ content: '文件下载失败', key: 'downloading', duration: 2 })
    // }
  }, 500)
</script>

<style lang="less" scoped>
  .data-content {
    display: flex;
    align-items: flex-start;
    padding-bottom: 24px;
    width: 100%;
    min-height: 590px;
    background: #fff;
    border: 1px solid #e8e9eb;
    border-radius: 10px;
    flex-direction: column;

    .header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 10px 24px;
      width: 100%;
      height: 56px;
      flex-direction: row;
      border-bottom: 1px solid rgba(0, 0, 0, 0.05);

      .header-title {
        display: flex;
        flex-direction: row;
        gap: 24px;

        .data-line {
          width: 1px;
          background: #d9d9db;
        }

        .data-size {
          color: rgba(17, 22, 31, 0.5);
        }

        .data-name {
          max-width: 300px;
        }
      }

      .header-down {
        .button-padding {
          padding: 7px 16px;
          gap: 6px;
          color: #1868e9;
        }
      }
    }

    .image-content {
      display: grid;
      overflow: hidden;
      padding: 16px;
      width: 100%;
      border-radius: 2px;
      grid-template-columns: repeat(6, 1fr);
      grid-auto-rows: 130px; /* 设置每行的高度为130px */
      grid-gap: 20px;

      .img {
        width: 100%;
        height: 100%;
        background: #f2f2f5;
        object-fit: contain;
      }
    }

    .down-more {
      width: 100%;
      font-size: 14px;
      text-align: center;
      color: rgba(17, 22, 31, 0.52);
      line-height: 22px;
    }
  }

  :deep(.ant-image) {
    img {
      width: 100%;
      height: 100%;
      background: #f2f2f5;
      object-fit: contain;
    }
  }
</style>
